<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1" name="viewport">
    <title>webrx</title>
</head>
<body>
<h2>fetch file upload</h2>
<input name="fs" type="file">
<button>上单文件</button>
<script>
    function upload() {
        let d = new FormData();
        var f = document.querySelector("input[name='fs']");

        d.append('id', 99);
        d.append('author', '李勇');
        d.append('photo', f.files[0]);

        fetch('upload.php', {
            method: 'POST',
            body: d
        }).then(e => e.json())
            .catch(e => console.error('Error:', e))
            .then(e => console.log('上传成功:', e));
    }

    let upbtn = document.querySelector('button')
    upbtn.addEventListener('click', upload)
</script>
</body>
</html>